//get items
let items=[];
const $ul = document.querySelector('ul'),
      url = 'http://192.168.142.166:8080/',
      $item = document.querySelector('input[type="text"]'),
      $form = document.querySelector('form');

function getItem(){
  //fetch request HTTP API
  fetch(url).then(res=>{
    res.text().then(txt=>{
      items = JSON.parse(txt)
      console.log(items);
      //generate DOM <li></li>
      const dom = items.map(item=>`<li>${item}</li>`).join('');
      $ul.innerHTML = dom;
    })
  });
}
getItem();

//add item event
$form.onsubmit = (e)=>{
  e.preventDefault();
  console.log($item.value);
  //fetch request HTTP API
  fetch(url,{method:'POST',body:`item=${$item.value}`}).then(res=>{
    getItem();
  });
}

